package org.lintcode_Close.Stage1_Easy_50.O3数组与循环;

/**
 * @Auther: qingle
 * @Date: 2024/8/17-17:55
 * @Description:
 * @version: 1.0
 */
public class 翻转字符串 {


	public String reverseWords(String s) {
		// write your code here
		//从后向前截取字符串，截取规则为：遇到空格截取单词
		String[] strs = s.split(" ");
		StringBuilder sb = new StringBuilder();
		for (int i = strs.length - 1; i >= 0; i--) {
			if (strs[i].length() > 0) {
				sb.append(strs[i]);
				sb.append(" ");
				sb.indexOf(" ");
			}
		}
		return sb.toString().trim();
	}

	public static void main(String[] args) {

		System.out.println(new 翻转字符串().reverseWords("the sky is blue"));
	}
}

